<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>挂号列表</title>
    <link rel="stylesheet" href="/component/pear/css/pear.css"/>
    <style type="text/css">
        .layui-form-select dl {
            max-height: 170px;
        }
    </style>
</head>
<body class="pear-container">

<div class="layui-card">
    <div class="layui-card-body">
        <form class="layui-form" action="">
            <div class="layui-form-item">
                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">挂号科室:</label>
                    <div class="layui-input-inline">
                        <select id="depId" name="depId">
                            <option value="">请选择挂号科室</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">患者名称:</label>
                    <div class="layui-input-inline">
                        <input type="text" name="patientName" placeholder="请输入患者名称" autocomplete="off"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">挂号类型:</label>
                    <div class="layui-input-inline">
                        <select id="type" name="type">
                            <option value="">请选择挂号类型</option>
                            <option value="1">门诊</option>
                            <option value="2">急诊</option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">挂号时段:</label>
                    <div class="layui-input-inline">
                        <select id="intervals" name="intervals">
                            <option value="">请选择挂号时段</option>
                            <option value="1">上午</option>
                            <option value="2">下午</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">挂号状态:</label>
                    <div class="layui-input-inline">
                        <select id="state" name="state">
                            <option value="">挂号状态</option>
                            <option value="1">待就诊</option>
                            <option value="2">就诊完成</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item layui-inline" style="margin-left: 30px;">
                    <button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="outpatient-query">
                        <i class="layui-icon layui-icon-search"></i>
                        查询
                    </button>
                    <button type="reset" class="pear-btn pear-btn-md">
                        <i class="layui-icon layui-icon-refresh"></i>
                        重置
                    </button>
                </div>
            </div>
        </form>
    </div>
</div>


<!--数据表格-->
<div class="layui-card">
    <div class="layui-card-body">
        <table id="outpatient-table" lay-filter="outpatient-table"></table>
    </div>
</div>


<script src="/component/layui/layui.js"></script>
<script src="/component/pear/pear.js"></script>
<script>
    layui.use(['table', 'form', 'jquery'], function () {
        let table = layui.table;
        let form = layui.form;
        let $ = layui.jquery;

        //加载下拉框
        $.get("/department/loadAllDepartment", function (data) {
            let depId = $("#depId");
            let html = '<option value="">请选择挂号科室</option>'
            $.each(data.data, function (i, item) {
                html += '<option value="' + item.id + '">' + item.name + '</option>'
            });
            depId.html(html);
            form.render();
        });

        let cols = [
            [
                {
                    title: '患者姓名',
                    field: 'patientName',
                    align: 'center',
                },
                {
                    title: '挂号科室',
                    field: 'depName',
                    align: 'center'
                },
                {
                    title: '接诊医生',
                    field: 'doctorName',
                    align: 'center',
                },
                {
                    title: '挂号费用',
                    field: 'price',
                    align: 'center',
                },
                {
                    title: '流水号',
                    field: 'number',
                    align: 'center',
                },
                {
                    title: '状态',
                    field: 'state',
                    align: 'center',
                    templet: function (d) {
                        let str;
                        if (d.state == 1) {
                            str = '<font>待就诊</font>';
                        } else if (d.state == 2) {
                            str = '<font style="color: green;">就诊完成</font>';
                        }
                        return str;
                    }
                },
                {
                    title: '挂号日期',
                    field: 'seeTime',
                    align: 'center',
                },
                {
                    title: '挂号类型',
                    field: 'type',
                    align: 'center',
                    templet: function (d) {
                        let str;
                        if (d.type == 1) {
                            str = '<font>门诊</font>';
                        } else if (d.type == 2) {
                            str = '<font>急诊</font>';
                        }
                        return str;
                    }
                },
                {
                    title: '挂号时段',
                    field: 'intervals',
                    align: 'center',
                    templet: function (d) {
                        let str;
                        if (d.intervals == 1) {
                            str = '<font>上午</font>';
                        } else if (d.intervals == 2) {
                            str = '<font>下午</font>';
                        }
                        return str;
                    }
                }
            ]
        ]

        var tableIns = table.render({
            elem: '#outpatient-table',
            url: '/outpatient/loadOutpatientPage',
            page: true,
            cols: cols,
            response: {
                statusCode: 200
            },
            done: function (res, curr, count) {
                if (res.data.length == 0 && curr != 1) {
                    tableIns.reload({
                        page: {
                            curr: (curr - 1)
                        }
                    });
                }
            },
        });

        //表头监听
        table.on('toolbar(outpatient-table)', function (obj) {
            if (obj.event === 'refresh') {
                window.refresh();
            }
        });

        //行监听
        table.on('tool(outpatient-table)', function (obj) {
            if (obj.event === 'remove') {
                remove(obj);
            } else if (obj.event === 'edit') {
                edit(obj);
            }
        });

        //表格监听
        form.on('submit(outpatient-query)', function (data) {
            table.reload('outpatient-table', {
                where: data.field
            })
            return false;
        });

        //   行 点击监听
        form.on('switch(outpatient-enable)', function (obj) {
            var id = $(this).attr('id');
            var state = '';
            obj.elem.checked ? state = '1' : state = '2';
            $.ajax({
                url: "/outpatient/updateoutpatientState/" + id + "/" + state,
                dataType: 'json',
                type: 'post',
                success: function (result) {
                    if (result.code == 200) {
                        layer.msg(result.msg, {
                            icon: 1,
                            time: 1000
                        });
                        tableIns.reload();
                    } else {
                        layer.msg(result.msg, {
                            icon: 2,
                            time: 1000
                        });
                    }
                }
            })

        });

        //删除
        function remove(obj) {
            layer.confirm('确定要删除?', {
                icon: 3,
                title: '提示'
            }, function (index) {
                layer.close(index);
                let loading = layer.load();
                $.ajax({
                    url: "/outpatient/deleteoutpatient/" + obj.data['id'],
                    dataType: 'json',
                    type: 'DELETE',
                    success: function (result) {
                        layer.close(loading);
                        if (result.code == 200) {
                            layer.msg(result.msg, {
                                icon: 1,
                                time: 1000
                            });
                            tableIns.reload();
                        } else {
                            layer.msg(result.msg, {
                                icon: 2,
                                time: 1000
                            });
                        }
                    }
                })
            });
        }


        window.refresh = function (param) {
            table.reload('outpatient-table');
        }

    })
</script>
</body>
</html>
